package com.java.mybatis.service.impl;

import com.java.mybatis.dao.DepartmentDao;
import com.java.mybatis.entity.Department;
import com.java.mybatis.service.DepartmentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Department)表服务实现类
 *
 * @author makejava
 * @since 2021-01-15 17:10:28
 */
@Service("departmentService")
public class DepartmentServiceImpl implements DepartmentService {
    @Resource
    private DepartmentDao departmentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param departmentId 主键
     * @return 实例对象
     */
    @Override
    public Department queryById(Integer departmentId) {
        return this.departmentDao.queryById(departmentId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Department> queryAllByLimit(int offset, int limit) {
        return this.departmentDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param department 实例对象
     * @return 实例对象
     */
    @Override
    public Department insert(Department department) {
        this.departmentDao.insert(department);
        return department;
    }

    @Override
    public int update(Department department) {
        return 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param departmentId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer departmentId) {
        return this.departmentDao.deleteById(departmentId) > 0;
    }
    /**
     * 查询所有部门信息的方法
     * @return 对象序列
     * */
    @Override
    public List<Department> queryAllDept() {
        return departmentDao.queryAllDept();
    }
    /**
     * 根据部门编号或者部门名称查询部门信息
     * @param departmentName 部门名称
     * @return 对象序列
     * */
    @Override
    public List<Department> selectByLike( String departmentName) {
        return this.departmentDao.selectByLike(departmentName);
    }
    /**
     *启用的方法
     **/
    @Override
    public void upDepartmentCodeUp(Integer id) throws Exception {
        this.departmentDao.upDepartmentCodeUp(id);
    }
    /**
     *禁用的方法
     **/
    @Override
    public void upDepartmentCodeDown(Integer id) throws Exception {
        this.departmentDao.upDepartmentCodeDown(id);
    }
}